/**
 * ...
 * @author Krzysztof Rozalski
 */

package hapi.facebook;
import php.Lib;
import php.NativeArray;

class FacebookAdapterConfig {

	public var appId(default, null):String;
	public var appSecret(default, null):String;
	public var appApi(default, null):String;
	public var baseUrl(default, null):String;
	public var appBaseUrl(default, null):String;
	public var cookie(default, null):Bool;
	public var isCanvas:Bool;
	public var requestedPermissions:Array<String>;
	
	public function new(appId, appSecret, appApi, baseUrl, appBaseUrl, ?isCanvas=true, ?cookie=true) {
		this.appApi = appApi;
		this.appId = appId;
		this.appSecret = appSecret;
		this.baseUrl = baseUrl;
		this.appBaseUrl = appBaseUrl;
		this.cookie = cookie;
		this.isCanvas = isCanvas;
		this.requestedPermissions = new Array();
	}
	
	public function addPermission(permission:String):Void {
		requestedPermissions.push(permission);
	}
	
	public function getUrlsConfig():NativeArray {
		var params:Hash<Dynamic> = new Hash<Dynamic>();
		params.set("canvas", isCanvas);
		params.set("fbconnect", !isCanvas);
		params.set("req_perms", requestedPermissions.join(","));
		return Lib.associativeArrayOfHash(params);
	}
	
	public function asPhpArray():NativeArray {
		var config:Hash<Dynamic> = new Hash<Dynamic>();
		config.set("appId", appId);
		config.set("api", appApi);
		config.set("secret", appSecret);
		config.set("baseUrl", baseUrl);
		config.set("appBaseUrl", appBaseUrl);
		config.set("cookie", cookie);
		return Lib.associativeArrayOfHash(config);
	}
}